//
//  WeiBoView.m
//  BV_WeiBo
//
//  Created by mac on 16/1/8.
//  Copyright © 2016年 YF_S. All rights reserved.
//

#define kThemeImageFormName(y) [[ThemeManager defaultThemeManager] imageWithName:y]

#import "WeiBoView.h"
#import "UIImageView+AFNetworking.h"
//#import "CommentViewController.h"

#import "HXGetPersonalNotifyDetailModel.h"

@implementation WeiBoView

//入口方法
-(void)awakeFromNib{

    //self.backgroundColor = [UIColor greenColor];
    
    //初始化textLabel
    _textLabel = [[CNLabel alloc]initWithFrame:CGRectMake(0, 0, HXSCREEN_WIDTH - 16, 0)];
    
    [self addSubview:_textLabel];
    
    //imgV的初始化
    _imgV = [[WBImageView alloc]initWithFrame:CGRectMake(25, 0, HXSCREEN_WIDTH-75, 0)];
    
    _imgV.contentMode = UIViewContentModeScaleAspectFill;
    
    [self addSubview:_imgV];
    
    //转发视图初始化  被转发的视图内容最多只可能存在两个控件 (label与imgV)
//    _repostWeiboView = [[WeiBoView alloc]initWithFrame:CGRectMake(0, 0, self.width, 0) withBOOL:YES];
//    [self addSubview:_repostWeiboView];
}

-(instancetype)initWithFrame:(CGRect)frame withBOOL:(BOOL)isrepost{

    self = [super initWithFrame:frame];
    
    if (self) {

        //是否为被转发微博
        self.isRepost = isrepost;
        
        //创建两个控件
        //创建 label
        //初始化textLable
        _textLabel = [[CNLabel alloc]initWithFrame:CGRectMake(5, 0, HXSCREEN_WIDTH - 16, 0)];
        
        [self addSubview:_textLabel];
        
        //imgV初始化
        _imgV = [[WBImageView alloc]initWithFrame:CGRectMake(25, 0, HXSCREEN_WIDTH - 75, 0)];
        
        _imgV.contentMode = UIViewContentModeScaleAspectFill;
        
        [self addSubview:_imgV];
   
//        if (self.isRepost) {
//            
//            //初始化_bgRepostImgV
////            _bgRepostImgV = [[ThemeImageV alloc]initWithImage:[kThemeImageFormName(@"timeline_rt_border_9") stretchableImageWithLeftCapWidth:25 topCapHeight:15]];
//            
////            //设置frame大小
////            _bgRepostImgV.frame = self.frame;
////            
////            //拉伸的参数
////            _bgRepostImgV.topDis = 15;
////            _bgRepostImgV.leftDis = 25;
////            
////            _bgRepostImgV.imageName = @"timeline_rt_border_9";
////            
////            //将背景视图插入到最底层
////            [self insertSubview:_bgRepostImgV atIndex:0];
//        }else{
//        
//            //转发视图初始化 被转发的视图内容最多只可能存在两个控件（label与imgV）
////            _repostWeiboView = [[WeiBoView alloc]initWithFrame:CGRectMake(0, 0, self.width, 0) withBOOL:YES];
//            
////            [self addSubview:_repostWeiboView];
//        }
    }
    
    return self;
}

-(void)setCompanyNotifierDataDic:(NSDictionary *)companyNotifierDataDic{

    _companyNotifierDataDic = companyNotifierDataDic;
    
    HXGetPersonalNotifyDetailShowModel * showModel = [_companyNotifierDataDic objectForKey:@"details"];
    
    NSArray * piclist = [_companyNotifierDataDic objectForKey:@"piclist"];
    
    //姓名
    _textLabel.text = [NSString stringWithFormat:@"通知详情：\n\n%@",showModel.Content];
    
    _textLabel.textLabelView.layer.borderWidth = 1.0f;
    _textLabel.textLabelView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    //HXReadDayWorkOrCommentPiclistModel
    
    //----------imgV-----------//
    CGFloat imgVH = 0;
    
    if (piclist.count > 0) {
        
        //根据文本 设置图片的Y轴
        //根据文本 设置图片的Y轴
        _imgV.top = _textLabel.bottom - 10;
        
        NSMutableArray *urls = [NSMutableArray array];
        
        for (HXGetPersonalNotifyDetailPictModel *picModel in piclist) {
            
            [urls addObject:picModel.Pic_Path];
        }
        
        //图片赋值数据
        _imgV.data = urls;
        
        //图片数据存在则不隐藏
        _imgV.hidden = NO;
        
        //重新赋值高度
        imgVH = _imgV.height;
    }else{
        
        //如果图片数据不存在则隐藏
        _imgV.hidden = YES;
    }
    //最终的self的高度是  自身的高度 和 label和imgV和_repostWeiboView的高度和
    self.height = imgVH + _textLabel.height;

    
}

-(void)setDataDic:(NSDictionary *)dataDic{

    _dataDic = dataDic;
    
    HXReadDayWorkOrCommentDetailsModel * detailModel = [_dataDic objectForKey:@"detail"];
    //姓名
    _textLabel.text = detailModel.Content;
    
    //HXReadDayWorkOrCommentPiclistModel
    
    //----------imgV-----------//
    CGFloat imgVH = 0;
    NSArray * piclistArr = [_dataDic objectForKey:@"piclist"];
    
    if (piclistArr.count > 0) {
        
        //根据文本 设置图片的Y轴
        //根据文本 设置图片的Y轴
        _imgV.top = _textLabel.bottom - 10;
        
        NSMutableArray *urls = [NSMutableArray array];
        
        for (HXReadDayWorkOrCommentPiclistModel *picModel in piclistArr) {
            
            [urls addObject:picModel.Pic_Path];
        }
        
        //图片赋值数据
        _imgV.data = urls;
        
        //图片数据存在则不隐藏
        _imgV.hidden = NO;
        
        //重新赋值高度
        imgVH = _imgV.height;
    }else{
        
        //如果图片数据不存在则隐藏
        _imgV.hidden = YES;
    }
    //最终的self的高度是  自身的高度 和 label和imgV和_repostWeiboView的高度和
    self.height = imgVH + _textLabel.height;

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    
}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

//    if (self.isRepost) {
//        
//        CommentViewController *commentTV = [[CommentViewController alloc]init];
//        
//        commentTV.weiboModel = self.model;
//        
//        [self.viewController.navigationController pushViewController:commentTV animated:YES];
//    }else{
//    
//        //再次判断当前微博视图所在的视图控制器对象是哪个类型
//        //如果不是微博详情视图控制器则推出新界面
//        if (![self.viewController isMemberOfClass:[CommentViewController class]]) {
//            
//            CommentViewController *commentTV = [[CommentViewController alloc]init];
//            
//            commentTV.weiboModel = self.model;
//            
//            [self.viewController.navigationController pushViewController:commentTV animated:YES];
//        }
//    }
    

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
